package com.ym.controller.management;


import com.github.pagehelper.PageInfo;
import com.ym.base.enums.FlagEnum;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;

import com.ym.medical.domain.entity.PhoneRuleEntity;
import com.ym.medical.domain.entity.TextRuleEntity;
import com.ym.medical.domain.param.ExamDoctorParam;
import com.ym.medical.domain.param.PhoneRuleModel;
import com.ym.medical.domain.param.TextRuleParam;
import com.ym.medical.domain.vo.DoctorServiceItemVO;
import com.ym.medical.domain.vo.DoctorServiceVO;
import com.ym.medical.service.IConsultSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 综合管理中心
 */
@Api(tags = "咨询配置管理")
@RestController
@RequestMapping("/management/consult")
public class ConsultManagement extends BaseController {

	@Autowired
	private IConsultSV consultSV;

	@ApiOperation("医生个人信息展示")
	@GetMapping("/serviceItem/doctor/list")
	public APIResponse<PageInfo<DoctorServiceItemVO>> doctorList(
			@ApiParam(name = "examDoctor", value = "咨询服务管理查询条件", required = true)
					ExamDoctorParam examDoctor,
			@RequestParam(required = false, defaultValue = "1") int pageNo,
			@RequestParam(required = false, defaultValue = "10") int limit) {
		PageInfo<DoctorServiceItemVO> info = consultSV.doctorList(examDoctor, pageNo, limit);
		return APIResponse.success("医生个人信息展示成功！", info);
	}

	@ApiOperation("医生咨询服务项展示")
	@GetMapping("/serviceItem/list")
	public APIResponse<List<DoctorServiceVO>> serviceItemList(@ApiParam(name = "doctorId", value = "医生id", required = true) @RequestParam Long doctorId,
															  @ApiParam(name = "seriLabel", value = "问诊方式（01-图文问诊 02-电话问诊 03-私人医生04视频问诊）", required = true)
															  @RequestParam String seriLabel,
															  @RequestParam(required = false, defaultValue = "1") int pageNo,
															  @RequestParam(required = false, defaultValue = "10") int limit) {
		List<DoctorServiceVO> doctorServiceVOs = consultSV.serviceItemList(doctorId, seriLabel, pageNo, limit);
		return APIResponse.success("医生咨询服务项展示成功！", doctorServiceVOs);
	}

	@ApiOperation("图文问诊服务次数配置新增")
	@PostMapping("/textRule/add")
	public APIResponse<TextRuleEntity> insertTextRule(@ApiParam(name = "textRule", value = "图文问诊对象", required = true) @Validated(value = {TextRuleParam.Add.class}) @RequestBody TextRuleParam textRule) {
		textRule.setIsDefault(FlagEnum.IS.getKey());
		TextRuleEntity textRule1 = consultSV.insertTextRule(textRule.covert());
		return APIResponse.success("图文问诊服务次数配置新增成功", textRule1);
	}

	@ApiOperation("图文问诊服务次数配置修改")
	@PostMapping("/textRule/update")
	public APIResponse<TextRuleEntity> updateTextRule(@ApiParam(name = "textRule", value = "图文问诊对象", required = true) @Validated(value = {TextRuleParam.Update.class}) @RequestBody TextRuleParam textRule) {
		TextRuleEntity textRule1 = consultSV.updateTextRule(textRule.covert());
		return APIResponse.success("图文问诊服务次数配置修改成功", textRule1);
	}

	@ApiOperation("图文问诊服务配置删除")
	@PostMapping("/textRule/delete")
	public APIResponse deleteTextRule(@ApiParam(name = "ids", value = "图文问诊id", required = true) @RequestBody Long[] ids) {
		consultSV.deleteTextRule(ids);
		return successMsg("图文问诊服务配置删除成功！");
	}

	@ApiOperation("图文问诊服务次数配置展示")
	@GetMapping("/textRule/list")
	public APIResponse<PageInfo<TextRuleEntity>> listTextRule(@ApiParam(name = "textRule", value = "图文问诊对象", required = true) @Validated(value = {TextRuleParam.Add.class})
																TextRuleParam textRule,
                                                        @RequestParam(required = false, defaultValue = "1") int pageNo,
                                                        @RequestParam(required = false, defaultValue = "10") int limit) {
		PageInfo<TextRuleEntity> info = consultSV.listTextRule(textRule, pageNo, limit);
		return APIResponse.success("图文问诊服务次数配置展示成功", info);
	}

	@ApiOperation("电话问诊服务时间配置新增")
	@PostMapping("/phoneRule/add")
	public APIResponse<PhoneRuleEntity> insertPhoneRule(@ApiParam(name = "phoneRule", value = "电话问诊对象", required = true) @Validated(value = {PhoneRuleModel.Add.class}) @RequestBody PhoneRuleModel phoneRule) {
		phoneRule.setIsDefault(FlagEnum.IS.getKey());
		PhoneRuleEntity phoneRule1 = consultSV.insertPhoneRule(phoneRule.covert());
		return APIResponse.success("电话问诊服务时间配置新增成功", phoneRule1);
	}

	@ApiOperation("电话问诊服务时间配置修改")
	@PostMapping("/phoneRule/update")
	public APIResponse<PhoneRuleEntity> updatePhoneRule(@ApiParam(name = "phoneRule", value = "电话问诊对象", required = true) @Validated(value = {PhoneRuleModel.Update.class}) @RequestBody PhoneRuleModel phoneRule) {
		PhoneRuleEntity phoneRule1 = consultSV.updatePhoneRule(phoneRule.covert());
		return APIResponse.success("电话问诊服务时间配置修改成功", phoneRule1);
	}

	@ApiOperation("电话问诊服务时间配置删除")
	@PostMapping("/phoneRule/delete")
	public APIResponse deletePhoneRule(@ApiParam(name = "ids", value = "电话问诊id", required = true) @RequestBody Long[] ids) {
		consultSV.deletePhoneRule(ids);
		return successMsg("电话问诊服务配置删除成功！");
	}

	@ApiOperation("电话问诊服务时间配置展示")
	@GetMapping("/phoneRule/list")
	public APIResponse<PageInfo<PhoneRuleEntity>> listPhoneRule(@ApiParam(name = "phoneRule", value = "电话问诊对象", required = true) @Validated(value = {PhoneRuleModel.Add.class})
																  PhoneRuleModel phoneRule,
                                                          @RequestParam(required = false, defaultValue = "1") int pageNo,
                                                          @RequestParam(required = false, defaultValue = "10") int limit) {
		PageInfo<PhoneRuleEntity> info = consultSV.listPhoneRule(phoneRule, pageNo, limit);
		return APIResponse.success("电话问诊服务时间配置展示成功", info);
	}
}
